using System;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;

namespace Charisma
{
    public class RepositoryConfigurator
    {
        internal Type ElementType;
        internal string MemberName;
        internal MemberInfo Member;
        internal string Name;
        internal KeyGeneratorKind KeyGeneratorKind;

        protected RepositoryConfigurator(Type elementType, string memberName)
        {
            Contract.Requires(elementType != null);
            Contract.Requires(!string.IsNullOrEmpty(memberName));

            ElementType = elementType;
            MemberName = memberName;
        }

        protected RepositoryConfigurator(Type elementType, MemberInfo member)
        {
            Contract.Requires(elementType != null);
            Contract.Requires(member != null);

            ElementType = elementType;
            MemberName = member.Name;
            Member = member;
        }
    }

    public class RepositoryConfigurator<T> : RepositoryConfigurator
    {
        public RepositoryConfigurator(string memberName)
            : base(typeof(T), memberName)
        {}

        public RepositoryConfigurator(MemberInfo member)
            : base(typeof(T), member)
        {}

        public RepositoryConfigurator<T> HasName(string name)
        {
            Contract.Requires(!String.IsNullOrEmpty(name));

            Name = name;
            return this;
        }

        public RepositoryConfigurator<T> HasKeyGenerator(KeyGeneratorKind keyGeneratorKind)
        {
            this.KeyGeneratorKind = keyGeneratorKind;
            return this;
        }
    }
}